﻿using B.S.DataBase.MyProject.Domain.基础设置;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
using MedicalPCTerminal.Write.API.Appcation.Commands.基础设置;

namespace MedicalPCTerminal.Write.API.Appcation.CommandHandlers.基础设置
{
    public class DelInstitutionCommandHandler : IRequestHandler<DelInstitutionCommand, APIResult<object>>
    {
        private readonly SqlSugarContext context;

        public DelInstitutionCommandHandler(SqlSugarContext context)
        {
            this.context = context;
        }

        public async Task<APIResult<object>> Handle(DelInstitutionCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            var entity=await context.db.Deleteable<Institution>(x=>x.InstitutionId==request.InstitutionId).ExecuteCommandAsync();
            if (entity > 0)
            {
                result.Code = APIEnum.删除成功;
                result.Msg = APIEnum.删除成功.ToString();
                result.data= entity;
            }
            else
            {
                result.Code = APIEnum.删除失败;
                result.Msg = APIEnum.删除失败.ToString();
                result.data = entity;
            }
            return await Task.FromResult(result);
        }
    }
}
